﻿#region Using directives

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

#endregion

namespace NCS_CS
{
  public class DataGridViewPronunciationCell : DataGridViewImageCell {

    public override object DefaultNewRowValue {
      // use this property to avoid tri-state value conditions in GetValue override,
      // rather than the default, which is that crossed-doc image
      get { return null; }
    }

    //protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContext context) {
    protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter,System.Windows.Forms.DataGridViewDataErrorContexts context)
    {
        // Update UI to show whether or not a sound exists
        if (value != null)
        {
            this.ToolTipText = "Click to hear pronunciation";
            return null;// Configuration.Resources.PlayMe;
        }
        else
        {
            //this.ToolTipText = "";
            return null;// Configuration.Resources.PlayMeNot;
        }
    }

    protected override void OnMouseEnter(int rowIndex) {
      // If a sound exists, change mouse cursor to something that might
      // help prompt the user to click the cell
      base.OnMouseEnter(rowIndex);
      if( base.GetValue(rowIndex) == null ) return;
      this.DataGridView.Cursor = Cursors.Hand;
    }

    protected override void OnMouseLeave(int rowIndex) {
      this.DataGridView.Cursor = Cursors.Default;
    }

    protected override void OnMouseClick(DataGridViewCellMouseEventArgs e) {
      if( e.Button != MouseButtons.Left ) return;
      object value = GetValue(RowIndex);

      if( value is byte[] ) {

        // Play sound
        byte[] sound = (byte[])value;
        MemoryStream stream = new MemoryStream(sound);
        //SoundPlayer player = new SoundPlayer(stream);
        //player.Play();
      }
    }
  }
}
